package Colecciones;

import Modelo.EjecutaConsulta;
import Modelo.TransaccionSql;
import java.io.PrintStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class Curso
{
  public static Vector listadoCursos(int p_reg)
  {
    Vector datos = new Vector();
    try {
      String consulta = " SELECT  CRSE_ID,   DESCR,   EFFDT  FROM  PS_CRSE_CATALOG WHERE  EFF_STATUS = 'A'";

      if (p_reg > 0)
        consulta = consulta + " AND ROWNUM <= " + String.valueOf(p_reg);

      datos = EjecutaConsulta.Ejecutar(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de Curso.listadoCursos " + e.toString());
    }
    return datos;
  }

  public static Vector getPsCrseCatalogByCrseId(String crse_id)
  {
    if (crse_id == null)
      crse_id = "";

    Vector datos = new Vector();
    try {
      String consulta = "SELECT CRSE_ID, EFFDT, EFF_STATUS, DESCR, EQUIV_CRSE_ID, CONSENT, ALLOW_MULT_ENROLL, UNITS_MINIMUM, UNITS_MAXIMUM, UNITS_ACAD_PROG, UNITS_FINAID_PROG, CRSE_REPEATABLE, UNITS_REPEAT_LIMIT, CRSE_REPEAT_LIMIT, GRADING_BASIS, GRADE_ROSTER_PRINT, COMPONENT, COURSE_TITLE_LONG, LST_MULT_TRM_CRS, CRSE_CONTACT_HRS, RQMNT_DESIGNTN, CRSE_COUNT, INSTRUCTOR_EDIT, FEES_EXIST, COMPONENT_PRIMARY, ENRL_UN_LD_CLC_TYP, DESCRLONG FROM  PS_CRSE_CATALOG WHERE   CRSE_ID = '" + crse_id + "' ";

      datos = EjecutaConsulta.Ejecutar(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de Curso.getPsCrseCatalogByCrseId " + e.toString());
    }
    return datos;
  }

  public static Vector getPsCrseComponentByCrseId(String crse_id)
  {
    if (crse_id == null)
      crse_id = "";

    Vector datos = new Vector();
    try {
      String consulta = "SELECT CRSE_ID, EFFDT, COMPONENT, OPTIONAL_SECTION, DEFAULT_SECT_SIZE, CONTACT_HOURS, FINAL_EXAM, EXAM_SEAT_SPACING, DYN_DT_INCLUDE, AUTO_CREATE_CMPNT, ATTEND_GENERATE, WEEK_WORKLOAD_HRS, OEE_WORKLOAD_HRS, LMS_FILE_TYPE FROM  PS_CRSE_COMPONENT WHERE  CRSE_ID = '" + crse_id + "' ";

      datos = EjecutaConsulta.Ejecutar(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de Curso.getPsCrseComponentByCrseId " + e.toString());
    }
    return datos;
  }

  public static Vector getPsCrseOfferByCrseId(String crse_id)
  {
    if (crse_id == null)
      crse_id = "";

    Vector datos = new Vector();
    try {
      String consulta = "SELECT CRSE_ID, EFFDT, CRSE_OFFER_NBR, INSTITUTION, ACAD_GROUP, SUBJECT, CATALOG_NBR, COURSE_APPROVED, CAMPUS, SCHEDULE_PRINT, CATALOG_PRINT, SCHED_PRINT_INSTR, ACAD_ORG, ACAD_CAREER, SPLIT_OWNER, SCHED_TERM_ROLL, RQRMNT_GROUP, CIP_CODE, HEGIS_CODE, USE_BLIND_GRADING, RCV_FROM_ITEM_TYPE, AP_ACCOUNT, AP_BUS_UNIT, AP_DEPTID, AP_FUND_CODE, AP_LEDGER, AP_PROG_CODE, AP_PROJ_ID, AP_BUDGET_PERIOD, AP_CLASS_FLD, AP_AFFILIATE, WRITEOFF_BUS_UNIT, WRITEOFF_ACCOUNT, WRITEOFF_FUND_CODE, WRITEOFF_PROG_CODE, WRITEOFF_PROJ_ID, WRITEOFF_LEDGER, WRITEOFF_DEPTID, WROF_BUDGET_PERIOD, WRITEOFF_CLASS_FLD, WRITEOFF_AFFILIATE, GL_INTERFACE_REQ, SEL_GROUP, SCHEDULE_COURSE, DYN_CLASS_DATA, OEE_IND, OEE_DYN_DATE_RULE, LMS_FILE_TYPE, OEE_WORKLOAD_HRS, WEEK_WORKLOAD_HRS, ATTEND_GENERATE, AUTO_CREATE_CMPNT, DYN_DT_INCLUDE, EXAM_SEAT_SPACING, FINAL_EXAM, CONTACT_HOURS, DEFAULT_SECT_SIZE, OPTIONAL_SECTION, COMPONENT FROM  PS_CRSE_OFFER WHERE  CRSE_ID = '" + crse_id + "' ";

      datos = EjecutaConsulta.Ejecutar(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de Curso.getPsCrseOfferByCrseId " + e.toString());
    }
    return datos;
  }

  public static int getCurrentCrseId()
    throws SQLException
  {
    String consulta = " SELECT  CRSE_ID_LAST CRSE_ID  FROM  PS_INSTALLATION_SA  FOR UPDATE ";

    ResultSet rs = TransaccionSql.ejecutarConsulta(consulta);
    rs.next();
    int emplid = rs.getInt("CRSE_ID_LAST");
    rs.close();
    return emplid;
  }

  public static String getNewCrseId()
    throws SQLException
  {
    int emplid = getCurrentCrseId() + 1;
    String consulta = " UPDATE    SYSADM.PS_INSTALLATION_SA SET   CRSE_ID_LAST = " + emplid;

    int result = TransaccionSql.actualizar(consulta);

    return String.valueOf(emplid);
  }
}